﻿using System.Web;
using Uber.Core.Service;
using Uber.Infra;

namespace Uber.WebUI
{
    public class Furious
    {
        public static void Pwn()
        {
            HttpContext.Current.Response.End();
        }

        public static string Target()
        {
            return HttpContext.Current.Request.UserHostAddress;
        }

        public static void CheckIm()
        {
            var value = Caching.Get(Target());

            if (value != null)
            {
                if (!(bool)value) Pwn();
            }
            else
            {
                if (IoC.Resolve<IBannedIps>().IsBanned(Target()))
                {
                    Caching.RegHost(Target(), false);
                    Pwn();
                }
                else
                {
                    Caching.RegHost(Target(), true);
                }
            }
        }
    }
}